home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / u_man / cat3 / Tcl / crtcommand.z / crtcommand
Text File  |  1998-10-30  |  15KB  |  199 lines

  1.  
  2.  
  3.  
  4. TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))                                TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Tcl_CreateCommand, Tcl_DeleteCommand, Tcl_GetCommandInfo,
  10.      Tcl_SetCommandInfo - implement new commands in C
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<ttttccccllll....hhhh>>>>
  14.  
  15.      Tcl_Command                                                              |
  16.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a, _d_e_l_e_t_e_P_r_o_c)
  17.  
  18.      int
  19.      TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd(_i_n_t_e_r_p, _c_m_d_N_a_m_e)
  20.  
  21.      int                                                                      |
  22.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _i_n_f_o_P_t_r)                             |
  23.  
  24.      int                                                                      |
  25.      TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _i_n_f_o_P_t_r)                             |
  26.  
  27.      char *                                                                   |
  28.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee(_i_n_t_e_r_p, _t_o_k_e_n)                                        |
  29.  
  30. AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  31.      Tcl_Interp          *_i_n_t_e_r_p           (in)      Interpreter in which to
  32.                                                      create new command.
  33.  
  34.      char                *_c_m_d_N_a_m_e          (in)      Name of command.
  35.  
  36.      Tcl_CmdProc         *_p_r_o_c             (in)      Implementation of new
  37.                                                      command:  _p_r_o_c will be
  38.                                                      called whenever _c_m_d_N_a_m_e
  39.                                                      is invoked as a command.
  40.  
  41.      ClientData          _c_l_i_e_n_t_D_a_t_a        (in)      Arbitrary one-word value
  42.                                                      to pass to _p_r_o_c and
  43.                                                      _d_e_l_e_t_e_P_r_o_c.
  44.  
  45.      Tcl_CmdDeleteProc   *_d_e_l_e_t_e_P_r_o_c       (in)      Procedure to call before
  46.                                                      _c_m_d_N_a_m_e is deleted from
  47.                                                      the interpreter; allows
  48.                                                      for command-specific
  49.                                                      cleanup.  If NULL, then
  50.                                                      no procedure is called
  51.                                                      before the command is
  52.                                                      deleted.
  53.  
  54.      Tcl_CmdInfo         *_i_n_f_o_P_t_r          (in/out)  Pointer to structure     |
  55.                                                      containing various       |
  56.                                                      information about a Tcl  |
  57.                                                      command.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))                                TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      Tcl_Command         _t_o_k_e_n             (in)      Token for command,       |
  75.                                                      returned by previous call|
  76.                                                      to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.    |
  77.                                                      The command must not have|
  78.                                                      been deleted.
  79.  
  80.  
  81. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  82.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd defines a new command in _i_n_t_e_r_p and associates it with
  83.      procedure _p_r_o_c such that whenever _c_m_d_N_a_m_e is invoked as a Tcl command
  84.      (via a call to TTTTccccllll____EEEEvvvvaaaallll) the Tcl interpreter will call _p_r_o_c to process
  85.      the command.  If there is already a command _c_m_d_N_a_m_e associated with the
  86.      interpreter, it is deleted.  TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd returns a token that may  |
  87.      be used to refer to the command in subsequent calls to                   |
  88.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee.  _P_r_o_c should have arguments and result that match the
  89.      type TTTTccccllll____CCCCmmmmddddPPPPrrrroooocccc:
  90.           typedef int Tcl_CmdProc(
  91.                ClientData _c_l_i_e_n_t_D_a_t_a,
  92.                Tcl_Interp *_i_n_t_e_r_p,
  93.                int _a_r_g_c,
  94.                char *_a_r_g_v[]);
  95.      When _p_r_o_c is invoked the _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p parameters will be copies
  96.      of the _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p arguments given to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.
  97.      Typically, _c_l_i_e_n_t_D_a_t_a points to an application-specific data structure
  98.      that describes what to do when the command procedure is invoked.  _A_r_g_c
  99.      and _a_r_g_v describe the arguments to the command, _a_r_g_c giving the number of
  100.      arguments (including the command name) and _a_r_g_v giving the values of the
  101.      arguments as strings.  The _a_r_g_v array will contain _a_r_g_c+1 values; the
  102.      first _a_r_g_c values point to the argument strings, and the last value is
  103.      NULL.
  104.  
  105.      _P_r_o_c must return an integer code that is either TTTTCCCCLLLL____OOOOKKKK, TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR,
  106.      TTTTCCCCLLLL____RRRREEEETTTTUUUURRRRNNNN, TTTTCCCCLLLL____BBBBRRRREEEEAAAAKKKK, or TTTTCCCCLLLL____CCCCOOOONNNNTTTTIIIINNNNUUUUEEEE.  See the Tcl overview man page
  107.      for details on what these codes mean.  Most normal commands will only
  108.      return TTTTCCCCLLLL____OOOOKKKK or TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR.  In addition, _p_r_o_c must set _i_n_t_e_r_p->_r_e_s_u_l_t to
  109.      point to a string value; in the case of a TTTTCCCCLLLL____OOOOKKKK return code this gives
  110.      the result of the command, and in the case of TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR it gives an error
  111.      message.  The TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt procedure provides an easy interface for
  112.      setting the return value;  for complete details on how the _i_n_t_e_r_p->_r_e_s_u_l_t
  113.      field is managed, see the TTTTccccllll____IIIInnnntttteeeerrrrpppp man page.  Before invoking a command
  114.      procedure, TTTTccccllll____EEEEvvvvaaaallll sets _i_n_t_e_r_p->_r_e_s_u_l_t to point to an empty string, so
  115.      simple commands can return an empty result by doing nothing at all.
  116.  
  117.      The contents of the _a_r_g_v array belong to Tcl and are not guaranteed to   |
  118.      persist once _p_r_o_c returns:  _p_r_o_c should not modify them, nor should it   |
  119.      set _i_n_t_e_r_p->_r_e_s_u_l_t to point anywhere within the _a_r_g_v values.  Call       |
  120.      TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt with status TTTTCCCCLLLL____VVVVOOOOLLLLAAAATTTTIIIILLLLEEEE if you want to return something   |
  121.      from the _a_r_g_v array.
  122.  
  123.      _D_e_l_e_t_e_P_r_o_c will be invoked when (if) _c_m_d_N_a_m_e is deleted.  This can occur
  124.      through a call to TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd or TTTTccccllll____DDDDeeeelllleeeetttteeeeIIIInnnntttteeeerrrrpppp, or by replacing
  125.      _c_m_d_N_a_m_e in another call to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.  _D_e_l_e_t_e_P_r_o_c is invoked
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))                                TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140.      before the command is deleted, and gives the application an opportunity
  141.      to release any structures associated with the command.  _D_e_l_e_t_e_P_r_o_c should
  142.      have arguments and result that match the type TTTTccccllll____CCCCmmmmddddDDDDeeeelllleeeetttteeeePPPPrrrroooocccc:
  143.  
  144.           typedef void Tcl_CmdDeleteProc(ClientData _c_l_i_e_n_t_D_a_t_a);
  145.  
  146.      The _c_l_i_e_n_t_D_a_t_a argument will be the same as the _c_l_i_e_n_t_D_a_t_a argument
  147.      passed to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.
  148.  
  149.      TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd deletes a command from a command interpreter.  Once the
  150.      call completes, attempts to invoke _c_m_d_N_a_m_e in _i_n_t_e_r_p will result in
  151.      errors.  If _c_m_d_N_a_m_e isn't bound as a command in _i_n_t_e_r_p then
  152.      TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd does nothing and returns -1;  otherwise it returns 0.
  153.      There are no restrictions on _c_m_d_N_a_m_e:  it may refer to a built-in
  154.      command, an application-specific command, or a Tcl procedure.
  155.  
  156.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo checks to see whether its _c_m_d_N_a_m_e argument exists as a|
  157.      command in _i_n_t_e_r_p.  If not then it returns 0.  Otherwise it places       |
  158.      information about the command in the structure pointed to by _i_n_f_o_P_t_r and |
  159.      returns 1.  Tcl_CmdInfo structures have fields named _p_r_o_c, _c_l_i_e_n_t_D_a_t_a,   |
  160.      and _d_e_l_e_t_e_P_r_o_c, which have the same meaning as the corresponding         |
  161.      arguments to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.  There is also a field _d_e_l_e_t_e_D_a_t_a, which |
  162.      is the ClientData value to pass to _d_e_l_e_t_e_P_r_o_c;  it is normally the same  |
  163.      as _c_l_i_e_n_t_D_a_t_a but may be set independently using the TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo  |
  164.      procedure.                                                               |
  165.  
  166.      TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo is used to modify the procedures and ClientData values|
  167.      associated with a command.  Its _c_m_d_N_a_m_e argument is the name of a command|
  168.      in _i_n_t_e_r_p.  If this command does not exist then TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo       |
  169.      returns 0.  Otherwise, it copies the information from *_i_n_f_o_P_t_r to Tcl's  |
  170.      internal structure for the command and returns 1.  Note that this        |
  171.      procedure allows the ClientData for a command's deletion procedure to be |
  172.      given a different value than the ClientData for its command procedure.   |
  173.  
  174.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee provides a mechanism for tracking commands that have  |
  175.      been renamed.  Given a token returned by TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd when the      |
  176.      command was created, TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee returns the string name of the   |
  177.      command.  If the command has been renamed since it was created, then     |
  178.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee returns the current name.  The command corresponding  |
  179.      to _t_o_k_e_n must not have been deleted.  The string returned by             |
  180.      TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddNNNNaaaammmmeeee is in dynamic memory owned by Tcl and is only         |
  181.      guaranteed to retain its value as long as the command isn't deleted or   |
  182.      renamed;  callers should copy the string if they need to keep it for a   |
  183.      long time.
  184.  
  185.  
  186. KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  187.      bind, command, create, delete, interpreter
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.